package com.kingyea.app.market.apiInterface.service.impl;

import com.kingyea.app.market.apiInterface.bean.ApiInterface;
import com.kingyea.app.market.apiInterface.dao.ApiInterfaceMapper;
import com.kingyea.app.market.apiInterface.service.ApiInterfaceService;
import com.kingyea.app.market.utils.StateCode;
import com.kingyea.app.market.utils.page.PageInfo;
import com.kingyea.mobilepolice.system.exception.BusinessException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @author
 * @version v1.0.0
 * @description ApiInterface 实现类
 * @date Created in 2018-02-09 17:58:06
 */
@Service
@Transactional
public class ApiInterfaceServiceImpl implements ApiInterfaceService {

    private static final Logger LOGGER = LoggerFactory.getLogger(ApiInterfaceServiceImpl.class);

    @Resource
    private ApiInterfaceMapper apiInterfaceMapper;

    /**
     * 通过ID查找对象
     *
     * @param id
     * @return
     */
    @Override
    public ApiInterface getById(String id) throws Exception {
        return this.apiInterfaceMapper.getById(id);
    }

    /**
     * 列表
     *
     * @param
     * @return
     */
    @Override
    public Object list(Map<String, Object> apiInterface) throws Exception {
        PageInfo.startPage(apiInterface);
        return PageInfo.getPageInfo(apiInterfaceMapper.list(apiInterface));
    }

    /**
     * 删除
     *
     * @param id
     * @return
     */
    @Override
    public int deleteById(String id) throws Exception {
        apiInterfaceMapper.deleteById(id);
        return 1;
    }

    /**
     * 保存
     *
     * @param apiInterface
     * @return
     */
    @Override
    public ApiInterface save(ApiInterface apiInterface) throws Exception {
        apiInterfaceMapper.save(apiInterface);
        return apiInterface;
    }

    /**
     * 更新
     *
     * @param apiInterface
     * @return
     */
    @Override
    public ApiInterface update(ApiInterface apiInterface) throws Exception {
        apiInterfaceMapper.update(apiInterface);
        return apiInterface;
    }

    @Override
    public Object deletesByAppCode(String appCode) throws Exception {
        if (org.apache.commons.lang3.StringUtils.isBlank(appCode)) {
            throw new BusinessException(StateCode.NO_ARGUMENT_ERROR);
        }
        return apiInterfaceMapper.deletesByAppCode(appCode);
    }


}
